package com.wfc.servlet.dish;

import com.wfc.entity.Dish;
import com.wfc.service.DishService;
import com.wfc.service.serviceImpl.DishServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/myDishServlet")
public class myDishServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        //根据用户名查找用户菜品
        DishService dishService = new DishServiceImpl();
        List<Dish> dishList = dishService.selectByuname(username);
        //session存入用户菜单
        HttpSession session = req.getSession();
        session.setAttribute("dishList",dishList);

        resp.setContentType("text/html; charset=utf-8");
        req.getRequestDispatcher("system/myCook.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是post请求");
        String username = req.getParameter("username");
        //根据用户名查找用户菜品
        DishService dishService = new DishServiceImpl();
        List<Dish> dishList = dishService.selectByuname(username);
        //session存入用户菜单
        HttpSession session = req.getSession();
        session.setAttribute("dishList",dishList);
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html; charset=utf-8");
        req.getRequestDispatcher("system/myCook.jsp").forward(req,resp);
    }
}
